package me.helllp.dake.generator.meta.core;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.squareup.javapoet.TypeSpec;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;

/**
 * 类的生成
 * 
 * @author 林晓明
 *
 */
@Getter
@Setter
public class SmartClass {
	private String name;
	
	private String desc;
	
	private List<SmartField> fields;
	
	private List<SmartMethod> methods;
	
	public TypeSpec.Builder builder() {
		return TypeSpec.classBuilder(name).addMethods(
					Optional.ofNullable(methods).map(item -> {
						return item.stream().map(parameter -> parameter.builder().build()).collect(Collectors.toList());
					}).orElse(Collections.emptyList())
				).addFields(
					Optional.ofNullable(fields).map(item -> {
						return item.stream().map(parameter -> parameter.builder().build()).collect(Collectors.toList());
					}).orElse(Collections.emptyList())
				).addJavadoc(StringUtils.isEmpty(desc) ? Strings.EMPTY : desc);
	}
}
